define (require, exports, module) ->
  module.exports =
    # 销毁滚动
    fixedDestroy: () ->
      window.onscroll = null

    # 滚动固定头部
    fixedTop: (options) ->
      elem_id = options?.elem_id
      mgt_top = options?.mgt_top

      elem = document.getElementById elem_id
      top = elem.offsetTop
      position = window.getComputedStyle(elem).position
      z_index = window.getComputedStyle(elem).zIndex
      width = window.getComputedStyle(elem).width

      setTimeout ->
        # 监听当前元素到顶部的距离
        listener = ->
          st = document.body.scrollTop or document.documentElement.scrollTop
          # 当滚动距离大于元素距离顶部高度时，固定元素
          if st > mgt_top
            elem.style.position = 'fixed'
            elem.style.top = '0'
            elem.style.zIndex = '9998'
            elem.style.width = width
          else
            elem.style.position = position
            elem.style.top = top
            elem.style.zIndex = z_index
            elem.style.width = width
          return

        # 滚动事件初始化
        window.onscroll = () ->
          listener()
          return
        return
      , 500

